package com.goodving.guli.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.model.Birthday;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.profile.scale.ScaleWeightInfo;
import com.goodving.guli.bt.ui.DimPanelBottomBar;
import com.goodving.guli.bt.ui.PickAdapter;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.view.C3657a;
import com.goodving.guli.view.C4220a;

import java.util.Calendar;

import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.WheelViewAdapter;

/**
 * Created by john on 2015/12/9.
 */
public class MemberInfoSetBirthActivity extends MemberInfoBaseActivity implements View.OnClickListener {
    private WheelView wheelViewYear;
    private WheelView wheelViewMonth;
    private TextView f11398j;
    private Birthday mBirthday;
    private int f11400l;
    private String f11401m;
    private PickAdapter mPickAdapter;
    private int mCurMonth;
    private boolean f11404p;
    private DimPanelBottomBar mDimPanelBottomBar;

    public MemberInfoSetBirthActivity() {
        this.f11401m = "2000-10-10";
        this.f11404p = false;
    }

    private void m15812a() {
        this.mBirthday.setYear(this.wheelViewYear.getRealCurrentItem() + this.f11400l); // m26810f
        this.mBirthday.setMonth(this.wheelViewMonth.getRealCurrentItem() + 1);
        this.f11401m = this.mBirthday.toStringData();
        GuliLog.tracePrintInfo("MemberInfoBaseActivity", "get birthday:" + this.mBirthday);
    }

    public void onCancel () { // m15815c
        m15812a();
        super.onCancel();
    }

    public void onConfirm () { // m15816d
        m15812a();
        if (!this.isVisitorMode) {
            super.onConfirm();
        }
        Keeper.saveCurrentUser(Keeper.CURRENT_USER_BIRTH, this.f11401m);
        // here i need to check if this is for person info
        PersonInfo personInfo = Keeper.readPersonInfo();
        if (personInfo.nickname.equals(Keeper.getCurrentUserInfoByTag(Keeper.CURRENT_USER_NAME)) &&
                String.valueOf(personInfo.uid).equals(Keeper.getCurrentUserInfoByTag(Keeper.CURRENT_USER_ID))) {
            // we need to get all these information
            personInfo.birthday = this.f11401m + C3657a.f18328f;
            Keeper.keepPersonInfo(personInfo);
        }

        Intent intent = new Intent();
        intent.setClass(this, MemberInfoSetHeightActivity.class);
        intent.putExtra(MemberInfoBaseActivity.setVisitorMode, this.isVisitorMode);
        intent.putExtra(MemberInfoBaseActivity.weightChooseUser, this.isWeightChooseUser);
        intent.putExtra("FROM_BABY_WEIGHT", this.f11404p);
        intent.putExtra(ScaleWeightInfo.WEIGHTADVDATA_KEY, this.f11393g == null ? C3657a.f18328f : this.f11393g.m25503n());
        startActivityForResult(intent, 6);
    }

    protected void onCreate(Bundle bundle) {
        int i;
        super.onCreate(bundle);
        this.isVisitorMode = getIntent().getBooleanExtra(MemberInfoBaseActivity.setVisitorMode, false);
        this.isWeightChooseUser = getIntent().getBooleanExtra(MemberInfoBaseActivity.weightChooseUser, false);
        this.f11404p = getIntent().getBooleanExtra("FROM_BABY_WEIGHT", false);
        if (!(getIntent() == null || getIntent().getExtras() == null)) {
            this.f11393g = ScaleWeightInfo.m25479b(getIntent().getStringExtra(ScaleWeightInfo.WEIGHTADVDATA_KEY));
        }
        setContentView((int) R.layout.activity_person_info_set_age);
        m15808b();
        this.f11398j = (TextView) findViewById(R.id.bracelet_login_title_info);
        this.f11398j.setText(getString(R.string.input_precise_user_info));
        String currentUserInfoByTag = Keeper.getCurrentUserInfoByTag(Keeper.CURRENT_USER_BIRTH);
        if (currentUserInfoByTag.isEmpty()) {
            i = Calendar.getInstance().get(Calendar.YEAR);
            int i2 = Calendar.getInstance().get(Calendar.MONTH) + 1;
            int i3 = Calendar.getInstance().get(Calendar.DATE);
            if (!this.f11404p) {
                this.f11401m = (i - 24) + "-7-15";
            } else if (i2 >= 7) {
                this.f11401m = i + "-" + (i2 - 6) + "-" + i3;
            } else {
                this.f11401m = (i - 1) + "-" + (i2 + 6) + "-" + i3;
            }
        } else {
            this.f11401m = currentUserInfoByTag;
        }
        this.mBirthday = Birthday.fromStr(this.f11401m);
        GuliLog.tracePrintInfo("MemberInfoBaseActivity", "onCreate, birthday:" + this.mBirthday);
        i = Calendar.getInstance().get(Calendar.YEAR);
        this.mCurMonth = Calendar.getInstance().get(Calendar.MONTH);
        this.f11400l = i - 100;
        int i4 = i + 0;
        this.wheelViewYear = (WheelView) findViewById(R.id.person_info_year_picker);
        //this.wheelViewYear.m26783a(5).setCenterDrawable(R.drawable.wheel_custom_val_dark_0).m26787a(getString(R.string.year), R.color.content_color, 12, C4220a.bh, C4220a.bj).m26788a(new PickAdapter(this, this.f11400l, i4, this.wheelViewYear, getResources().getColor(R.color.title_color), getResources().getColor(R.color.content_color), getResources().getColor(R.color.content_color_darker), false, 50, 48, 45, 45));
        this.wheelViewYear.setVisibleItems(5).setCenterDrawable(R.drawable.wheel_custom_val_dark_0).setCenterStyle(getString(R.string.year),
                R.color.content_color, 12, C4220a.bh, C4220a.bj).setViewAdapter(new PickAdapter(this, this.f11400l, i4, this.wheelViewYear,
                getResources().getColor(R.color.title_color),
                getResources().getColor(R.color.content_color),
                getResources().getColor(R.color.content_color_darker), false, 50, 48, 45, 45));


        this.wheelViewMonth = (WheelView) findViewById(R.id.person_info_month_picker);
        this.mPickAdapter = new PickAdapter(this, 1, 12, this.wheelViewMonth,
                getResources().getColor(R.color.title_color),
                getResources().getColor(R.color.content_color),
                getResources().getColor(R.color.content_color_darker), true, 50, 48, 45, 45);
        if (!this.mBirthday.isValid() || this.mBirthday.getYear() - this.f11400l < 100) {
            this.wheelViewMonth.setVisibleItems(5).setCenterDrawable(R.drawable.wheel_custom_val_dark_0).setCenterStyle(getString(R.string.month),
                    R.color.content_color, 12, C4220a.bi, C4220a.bj).setViewAdapter(this.mPickAdapter);
        } else {
            this.wheelViewMonth.setVisibleItems(5).setCenterDrawable(R.drawable.wheel_custom_val_dark_0).setCenterStyle(getString(R.string.month),
                    R.color.content_color, 12, C4220a.bi, C4220a.bj).setViewAdapter(new PickAdapter(this, 1, this.mCurMonth + 1,
                    this.wheelViewMonth,
                    getResources().getColor(R.color.title_color),
                    getResources().getColor(R.color.content_color),
                    getResources().getColor(R.color.content_color_darker), false, 50, 48, 45, 45));
        }
        if (this.mBirthday.isValid()) {
            this.wheelViewYear.setCurrentItem(this.mBirthday.getYear() - this.f11400l);  // m26804c
            this.wheelViewMonth.setCurrentItemLooped(this.mBirthday.getMonth() - 1); // m26806d
        } else {
            this.wheelViewYear.setCurrentItem(1990 - this.f11400l);
            this.wheelViewMonth.setCurrentItemLooped(0);
        }
        this.wheelViewYear.addScrollingListener(new C2016a(this)); // m26794a
        this.mDimPanelBottomBar = (DimPanelBottomBar) findViewById(R.id.bottom_bar);
        this.mDimPanelBottomBar.m14980a(getResources().getColor(R.color.content_color));
        this.mDimPanelBottomBar.m14983b(getResources().getColor(R.color.title_color));
    }

    class C2016a implements OnWheelScrollListener  { // C1825e
        final /* synthetic */ MemberInfoSetBirthActivity memberInfoSetBirthActivity; // f11466a

        C2016a(MemberInfoSetBirthActivity memberInfoSetBirthActivity) {
            this.memberInfoSetBirthActivity = memberInfoSetBirthActivity;
        }

        public void onScrollingStarted (WheelView wheelView) {  //m15855a
            GuliLog.tracePrintInfo("MemberInfoBaseActivity", "onScrollingStarted " + wheelView.getRealCurrentItem());
        }

        public void onScrollingFinished (WheelView wheelView) { // m15856b
            int i = 0;
            GuliLog.tracePrintInfo("MemberInfoBaseActivity", "onScrollingFinished " + wheelView.getRealCurrentItem());
            if (100 == wheelView.getRealCurrentItem()) {
                GuliLog.tracePrintInfo("MemberInfoBaseActivity", " should refresh month");
                WheelViewAdapter dmVar = new PickAdapter(this.memberInfoSetBirthActivity, 1,
                        this.memberInfoSetBirthActivity.mCurMonth + 1,
                        this.memberInfoSetBirthActivity.wheelViewMonth,
                        this.memberInfoSetBirthActivity.getResources().getColor(R.color.title_color),
                        this.memberInfoSetBirthActivity.getResources().getColor(R.color.content_color),
                        this.memberInfoSetBirthActivity.getResources().getColor(R.color.content_color_darker), false, 50, 48, 45, 45);
                WheelView b = this.memberInfoSetBirthActivity.wheelViewMonth;
                if (this.memberInfoSetBirthActivity.mCurMonth + 1 < 0) {
                    i = this.memberInfoSetBirthActivity.mCurMonth + 1;
                }
                b.setCurrentItem(i);
                this.memberInfoSetBirthActivity.wheelViewMonth.setViewAdapter(dmVar); //m26788a
                return;
            }
            this.memberInfoSetBirthActivity.wheelViewMonth.setViewAdapter(this.memberInfoSetBirthActivity.mPickAdapter);
        }
    }

    protected void onPause() {
        super.onPause();
        C0668a.m8141b(C0668a.aO);
        C0668a.m8138b((Activity) this);
    }

    protected void onResume() {
        super.onResume();
        C0668a.m8133a(C0668a.aO);
        C0668a.m8124a((Activity) this);
    }
}
